package com.jinbei.restController;

import com.jinbei.common.annotation.AuthorAnnotation;
import com.jinbei.common.base.ResponseBase;
import com.jinbei.common.base.ResponseBaseEntity;
import com.jinbei.domain.Message;
import com.jinbei.service.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zflu
 * socket消息 restful 接口
 * Created by lucky on 2018/8/20.
 */
@RestController
@RequestMapping("/message")
public class MessageController {

    private final Logger logger = LoggerFactory.getLogger(MessageController.class);

    @Autowired
    private MessageService messageService;

    /**
     * @author zflu
     * @Description   查询消息详情
     * @date 2018/8/20 13:30
     * @param id
     * @return com.jinbei.common.base.ResponseBase
     */
    @AuthorAnnotation( logs = "消息详情查询" , flag = false)
    @GetMapping("/queryMessageById")
    public ResponseBase queryMessageById(@RequestParam("id") int id){
        try {
            Message message = messageService.queryMessageById(id);
            return ResponseBaseEntity.setResultSuccess(message);
        }catch (Exception e){
            logger.error("查询消息详情失败!  {}",e);
            return ResponseBaseEntity.setResultError(null);
        }
    }

    /**
     * @author zflu
     * @Description   查询消息列表
     * @date 2018/8/20 13:30
     * @param
     * @return com.jinbei.common.base.ResponseBase
     */
    @AuthorAnnotation( logs = "消息列表查询" , flag = false)
    @GetMapping("/queryMessageList")
    public ResponseBase queryMessageList(){
        try {
            List<Message> messages = messageService.queryMessageList();
            return ResponseBaseEntity.setResultSuccess(messages);
        }catch (Exception e){
            logger.error("查询消息列表失败!  {}",e);
            return ResponseBaseEntity.setResultError(null);
        }
    }

}
